package org.colcon.web.model.vote;

import java.util.HashMap;
import java.util.Map;

import org.colcon.web.model.framework.IBallot;
import org.colcon.web.server.CLI;

public class ConfirmationVote extends SelectionVote
{
	public String getType(){return "confirmation_vote";}
	
	private static final long serialVersionUID = 8344932604318527159L;
	
	private static final String
	
		// values
		YES = "yes",
		NO = "no";
	
	public ConfirmationVote()
	{
		this(new HashMap<String, String>());
	}
	
	public ConfirmationVote(Map<String, String> args)
	{
		this(
				args.get(PARENT), 
				args.get(ID), 
				args.get(TEXT),
				args.get(COMMAND), 
				args.get(CHILDREN)
		);
	}
	
	public ConfirmationVote(String parent, String id, String text, String command, String children)
	{
		super(parent, id, text, command, YES + ' ' + NO, children);
	}
	
	public String getResult(IBallot[] ballots)
	{
		if(getCommand() == null || getValue(ballots) == null || !getValue(ballots).equals(YES))
			return CLI.NULL;
		
		return getCommand();
	}
}
